package kr.saeildamil.androidstudy_second.animation;

import java.util.ArrayList;

import kr.saeildamil.androidstudy_second.R;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
import android.widget.ViewSwitcher.ViewFactory;

public class ImageSwitcherTest extends Activity	{
	ImageSwitcher mImageSwitcher;
	int mImageIdx;
	ArrayList<Drawable> imgs;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_textswitchertest);
		
		imgs = new ArrayList<Drawable>();
		imgs.add(getResources().getDrawable(R.drawable.babydrum));
		imgs.add(getResources().getDrawable(R.drawable.babydrum1));
		imgs.add(getResources().getDrawable(R.drawable.korandoc));
		imgs.add(getResources().getDrawable(R.drawable.mugung));
		mImageSwitcher = (ImageSwitcher) findViewById(R.id.ch23_textswitcher_imageswitcher);
		
		mImageSwitcher.setFactory(mImageFactory);
		mImageSwitcher.setImageDrawable(imgs.get(mImageIdx));
	}
	
	ViewSwitcher.ViewFactory mImageFactory = new ViewFactory() {
		public View makeView() {
			ImageView img = new ImageView(ImageSwitcherTest.this);
			return img;
		}
	};
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.ch23_textswitcher_btnnext:
			mImageIdx = mImageIdx==imgs.size()-1?0:mImageIdx+1;
			mImageSwitcher.setImageDrawable(imgs.get(mImageIdx));
			break;
		}
	}
	
}
